import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:get/get.dart';

class CustomAppBottomBarController extends GetxController {

  var hasNetWork = false.obs;
  var mNetSubscription =  null;

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
    monitorNetWork();
  }


  void monitorNetWork() async {
    final List<ConnectivityResult> connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult.contains(ConnectivityResult.mobile) || connectivityResult.contains(ConnectivityResult.wifi)) {
      hasNetWork.value = true;

    } else {
      hasNetWork.value = false;

    }


    mNetSubscription = Connectivity().onConnectivityChanged.listen((List<ConnectivityResult> result) {
      // Received changes in available connectivity types!
      if (result.contains(ConnectivityResult.mobile) || result.contains(ConnectivityResult.wifi)) {
        hasNetWork.value = true;
      } else {
        hasNetWork.value = false;
      }

    });
  }


}